﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace DataAccess
{
    public class FS0103_SubDataAccess:FSBase_DataAccess
    {
        #region 根据需求编号获取需求信息
        public DataTable getRequirement(string strRequirementNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("     select * from tRequirement where vcRequirementNo = '" + strRequirementNo + "'    ");
            return Search(strSql.ToString());
        }
        #endregion

        #region 通过iAutoID检索需求信息
        public DataTable getRequirementInfo(string strAutoID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("      select iAutoID, vcRequirementNo, vcCategory, vcRequirementName, vcRequirementDescription, vcRequirementPic, vcRequirementPicName from tRequirement where iAutoID = " + strAutoID + "       ");
            return Search(strSql.ToString());
        }
        #endregion

        #region 保存
        public void Save(string strRequirementNo, string strCategory, string strRequirementName, string strRequirementDescription, byte[] byteRequirementPic, string strRequirementPicName)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("     insert into tRequirement(vcRequirementNo,vcCategory,vcRequirementName,vcRequirementDescription,vcRequirementPic,vcRequirementPicName) values    ");
            strSql.AppendLine("     ('" + strRequirementNo + "','" + strCategory + "','" + strRequirementName + "','" + strRequirementDescription + "',@vcRequirementPic,'" + strRequirementPicName + "')    ");
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("@vcRequirementPic", byteRequirementPic);
            update(strSql.ToString(), parameters);
        }
        #endregion
        #region 修改
        public void Modify(string strAutoID,string strRequirementNo, string strCategory, string strRequirementName, string strRequirementDescription, byte[] byteRequirementPic, string strRequirementPicName)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("       update tRequirement set       ");
            strSql.AppendLine("        vcRequirementNo = '"+strRequirementNo+"'      ");
            strSql.AppendLine("       ,vcCategory = '"+strCategory+"'      ");
            strSql.AppendLine("       ,vcRequirementName = '"+strRequirementName+"'      ");
            strSql.AppendLine("       ,vcRequirementDescription = '"+strRequirementDescription+"'      ");
            strSql.AppendLine("       ,vcRequirementPic = @vcRequirementPic       ");
            strSql.AppendLine("       ,vcRequirementPicName = '"+strRequirementPicName+"'      ");
            strSql.AppendLine("       where iAutoID = "+strAutoID+"       ");
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("@vcRequirementPic", byteRequirementPic);
            update(strSql.ToString(), parameters);
        }
        #endregion
    }
}
